package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Override
    public List<Role> getRoleByUserId(Integer id) {
        List<Role> roles = userMapper.getRoleByUserId(id);
        List<Role> list = new ArrayList<>();
        for (Role role : roles) {
            list.add(userMapper.getRoleById(role.getRoleId()));
        }
        return list;
    }

    @Autowired
    private UserMapper userMapper;

    /**
     * 根据用户名获取用户信息
     * @param username
     * @return
     */
    @Override
    public List<User> getUser(String username) {
        List<User> users = userMapper.getUser(username);
//        if(users == null || users.size() == 0){
//            throw new UsernameNotFoundException("");
//        }
        return users;
    }
}
